const mongoose = require('mongoose');
const md5 = require('blueimp-md5')
// 用户表字段规则
const userSchema = new mongoose.Schema({
    username: {type: String,require: true},
    name: {type: String,require: true},
    password: {type: String,require: true},
    phone: String,
    create_time: {type: Number,default: Date.now},
    role_id: { type: String},
})
// 创建用户表
const UserModel = mongoose.model('users',userSchema)
// 查询表中是否有admin这个用户，如果没有就添加
UserModel.findOne({username:'admin'}).then(user=>{
    if(!user){
        // 添加超级管理员
        UserModel.create({username:'admin',password:md5('admin'),name:'超级管理员'}).then(data=>{
            console.log('初始化用户，用户名:admin，密码:admin');
        })
    }
})
module.exports = UserModel